package router

import (
	"crow-samba/app/service"
	"github.com/gin-gonic/gin"
)

// GetSambaConf 获取samba配置
// @Summary 获取samba配置
// @Description 获取samba配置，该接口仅作为开发调试
// @Tags conf
// @Success 200 {object} response.Response{data=service.SambaConfig} "{"requestId": "string","code": 200,"msg": "ok","data": [...]}"
// @Failure 500 {object} response.Response{msg=string} "{"requestId": "string","code": 500,"msg": "string","status": "error","data": null}"
// @Router /api/v1/conf [get]
// @Security Bearer
func GetSambaConf(c *gin.Context) {
	var s service.SambaConfig
	err := s.GetConf()
	if err != nil {
		SetErrDefault(c, err)
		return
	}
	SetOK(c, s)
}

// WriteSambaConf 写入配置文件
// @Summary 写入配置文件
// @Description 写入配置文件，该接口仅作为开发调试
// @Tags conf
// @Accept  application/json
// @Product application/json
// @Param data body service.SambaConfig  true "配置信息"
// @Success 200 {object} response.Response{data=string} "{"requestId": "string","code": 200,"msg": "ok","data": [...]}"
// @Failure 500 {object} response.Response{msg=string} "{"requestId": "string","code": 500,"msg": "string","status": "error","data": null}"
// @Router /api/v1/conf [post]
// @Security Bearer
func WriteSambaConf(c *gin.Context) {
	var s service.SambaConfig
	err := c.Bind(&s)
	if err != nil {
		SetErrDefault(c, err)
		return
	}
	r, err := s.WriteConf()
	if err != nil {
		SetErrDefault(c, err)
		return
	}
	SetOK(c, "创建成功 "+r)
}
